/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package opds.kurs.work.core;

/**
 *
 * @author pol
 */
public class Util {

    public static int[][] getMatrixG(int[] polinom) {
        int[][] g = new int[5][15];
        for (int i = 4; i >= 0; i--) {
            for (int j = 14; j >= 0; j--) {
                if (polinom[j] == 1) {
                    g[4 - i][j - i] = 1;
                }
            }
        }
        for (int j = 4; j > -1; j--) {
            for (int i = 0; i < 5; i++) {
                if ((i != j) && (g[i][j] != 0)) {
                    for (int k = 0; k < 15; k++) {
                        if (g[i][k] == g[j][k]) {
                            g[i][k] = 0;
                        } else {
                            g[i][k] = 1;
                        }
                    }
                }
            }
        }
        return g;
    }

    public static int[][] getMatrixH(int[][] g) {
        int[][] h = new int[10][15];
        for (int i = 0; i < 5; i++) {
            for (int j = 5; j < 15; j++) {
                h[j - 5][i] = g[i][j];
            }
        }
        for (int i = 0; i < 10; i++) {
            for (int j = 5; j < 15; j++) {
                h[i][j]=0;
                if(i==(j-5)) {
                    h[i][j]=1;
                }
            }
        }
        return h;
    }
}
